<?php

namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\DormMeterRecord;

/**
 * Class DormMeterRecordTransformer.
 *
 * @package namespace App\Transformers;
 */
class DormMeterRecordTransformer extends TransformerAbstract
{
    /**
     * Transform the DormMeterRecord entity.
     *
     * @param \App\Models\DormMeterRecord $model
     *
     * @return array
     */
    public function transform(DormMeterRecord $model)
    {
        return [
            'id'         => (int) $model->id,
            'company' => $model->company,
            'period_id'         => $model->period_id,
            'period_name'         => optional($model->period)->name,
            'dorm_id'         => $model->dorm_id,
            'dorm_code'         => optional($model->dorm)->code,
            'user_id'         => $model->user_id,
            'client_id'         => $model->client_id,
            'user_name'         => optional($model->user)->name,
            'meter_type_id'         => $model->meter_type_id,
            'meter_type'         => optional($model->meterType)->name,
            'meter_reading'         => $model->meter_reading,
            'prev_meter_reading'         => $model->prev_meter_reading,
            'meter_reading_date'         => $model->meter_reading_date,
            'consume'         => $model->consume,
            'remark'         => $model->remark,

            /* place your other model properties here */

            'created_at' => $model->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $model->updated_at->format('Y-m-d H:i:s')
        ];
    }
}
